Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Woo POS] Coupons: Creation (with dummy entry point UI) #15467

Merged
merged 10 commits into from
Apr 3, 2025

Conversation

staskus
Copy link
Contributor

@staskus staskus commented Apr 1, 2025

Description

On POS, show existing IPP Coupon creation via a dummy entry point UI.

The main goal was to reuse two existing views:

  • AddEditCoupon
  • BottomSheetListSelectorViewController

I emulated the flow from the IPP flow:
Show BottomSheetListSelectorViewController for selecting coupon type (percentage / fixed) and then show AddEditCoupon for configuring the view.

I created POSCouponCreationSheet to encapsulate all the logic. The main complexity was around all the completion handlers so the modal dismissing and navigation would work properly on POS with SwiftUI.

The most notable change was to only refresh the view when the coupon success view is dismissed, not when the coupon code is successfully created to avoid issues that happen when the list is refreshed and the sheet still presented.

Steps to reproduce

Prerequisites: Enable enableCouponsInPointOfSale feature flag

  1. Open POS
  2. Select Coupons
  3. Tap +, confirm 'Discount Type Selection' sheet appears
  4. Confirm cancel closes, confirm cannot be dismissed with gesture
  5. Select discount type, confirm 'Coupon Creation' sheet opens
  6. Try to navigate in as many views as possible, change coupon codes, change values, change restrictions, dismiss and reopen
  7. After configuring, tap create
  8. Confirm success view appears
  9. Dismiss the success view
  10. Confirm coupon list is refreshed and a new coupon appears
  11. Try to apply the coupon
  12. Confirm the application works as expected

Testing information

Tested on both iOS 18 and iOS 17 to confirm that modal presentation works correctly. Put focus on testing as many dismissal, coming back and success combinations as possible.

Screenshots

new_coupon_flow.mp4

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

staskus added 3 commits April 1, 2025 16:10
Display two existing views to emulate the IPP behavior:
- Display discount type selector via BottomSheetListSelector
- Display coupon creation view via AddEditCoupon
@staskus staskus added type: task An internally driven task. feature: POS labels Apr 1, 2025
@staskus staskus added this to the 22.1 milestone Apr 1, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Apr 1, 2025

1 Warning
⚠️ This PR is assigned to the milestone 22.1. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 1, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Number29158
VersionPR #15467
Bundle IDcom.automattic.alpha.woocommerce
Commit5efb9d0
Installation URL2o171rr470slg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@staskus staskus changed the title [Woo POS] Coupons: Creation - Dummy Entry Point UI [Woo POS] Coupons: Creation (with dummy entry point UI) Apr 2, 2025
@staskus staskus marked this pull request as ready for review April 2, 2025 12:00
@staskus staskus requested a review from iamgabrielma April 2, 2025 12:00
Copy link
Contributor

@iamgabrielma iamgabrielma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! 🚢

For a separate PR (maybe not needed): I happened to have coupons disabled from Woo Settings when I was initially testing this:

⛔️ Error creating the coupon: Sorry, there was an issue with the server. Please try again later. (Error code: 403). Response: {"code":"woocommerce_rest_cannot_create","message":"Sorry, you are not allowed to create resources.","data":{"status":403}}
🔵 Tracked coupon_creation_failed, properties: [error_description: Sorry, there was an issue with the server. Please try again later. (Error code: 403). Response: {"code":"woocommerce_rest_cannot_create","message":"Sorry, you are not allowed to create resources.","data":{"status":403}}, blog_id: -1, error_domain: Networking.NetworkError, plan: , store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, error_code: 2, site_url: https://indiemelon.mystagingwebsite.com, is_wpcom_store: false, was_ecommerce_trial: false]

This happens after selecting the coupon type and filling all the info in the last step before creating it, which might be annoying, perhaps we want to add a call to check the coupon settings when we first tap on "+" and show some toast notification to enable coupons.

That said maybe nothing is necessary since we do this call as soon as we switch to the coupons tab and present an error screen, we just have to remember to disable the button or hide it on that case 👍

@@ -6,7 +6,7 @@ final class AddEditCouponHostingController: UIHostingController<AddEditCoupon> {

private let viewModel: AddEditCouponViewModel

init(viewModel: AddEditCouponViewModel, onDisappear: @escaping () -> Void) {
init(viewModel: AddEditCouponViewModel, onDisappear: @escaping (_ success: Bool) -> Void) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success parameter makes sense in the context of this PR, but if I saw it out of the blue it might be tricky to understand what's the success referring to, like "success of disappear"? Would it make sense to rename the param to something like isCouponCreationSuccess, couponCreateResultCallback, or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. If question like this comes up, then it definetely makes sense to clarify it 👍

@iamgabrielma iamgabrielma self-assigned this Apr 3, 2025
@staskus
Copy link
Contributor Author

staskus commented Apr 3, 2025

That said maybe nothing is necessary since we do this call as soon as we switch to the coupons tab and present an error screen, we just have to remember to disable the button or hide it on that case 👍

I agree. I added that to the project requirements pdfdoF-6BG-p2

@staskus staskus enabled auto-merge April 3, 2025 11:24
@staskus staskus merged commit 89dc2a7 into trunk Apr 3, 2025
13 checks passed
@staskus staskus deleted the task/WOOMOB-212-woo-pos-coupon-creation branch April 3, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants